﻿using System;
using System.Security;
using System.Web;
using System.Web.UI;
using CARMS;

namespace CARMS
{
    public class UserControlBase : UserControl
    {
        public static string CurrentFunction
        {
            get
            {
                return HttpContext.Current.Session["CurrentFunctionID"].ToString();
            }
        }
        protected new PageBase Page
        {
            get
            {
                var page = base.Page as PageBase;
                if (page == null)
                {
                    throw new VerificationException("The page must be inherit from Page Base.");
                }
                return page;
            }
        }



        protected void RediretResolveUrl(string strUrl)
        {
            Response.Redirect(ResolveUrl(strUrl));
        }

        public bool MenuLoaded
        {
            get
            {
                return Page.MenuLoaded;

            }
            set { Page.MenuLoaded = value; }
        }

        public UserData CurrentControlLoginUser
        {
            get
            {
                return (UserData)Session["CurrentLoginUser"];
            }
            set
            {
                Session["CurrentLoginUser"] = value;
            }
        }

        public string GetStringByParameter(string strParameterName)
        {
            if (Request.QueryString[strParameterName] != null)
            {
                return Request.QueryString[strParameterName];
            }

            return string.Empty;
        }

        public Guid GetGuidByParameter(string strParameterName)
        {
            if (Request.QueryString[strParameterName] != null)
            {
                return new Guid(Request.QueryString[strParameterName]);
            }

            return Guid.Empty;
        }


        protected virtual void Alert(string message)
        {
            Page.Alert(message);
        }
        protected virtual void ScriptStartup(string scriptContent)
        {
            Page.ScriptStartup(scriptContent);
        }
    }
}
